<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="../../static/admin/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/admin/css/admin.css"/>
</head>
<body>
<div class="layui-tab page-content-wrap">
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <form class="layui-form"  style="width: 90%;padding-top: 20px;">
                {% csrf_token %}
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">ID：</label>
                    <div class="layui-input-block">
                        <input type="text" name="id" disabled autocomplete="off" class="layui-input" value={{P_id}}>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">参数名：</label>
                    <div class="layui-input-block">
                        <input type="text" name="zdbm" lay-verify="zdkey" placeholder="请输参数名" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">参数值：</label>
                    <div class="layui-input-block">
                        <input type="text" name="zdmc" lay-verify="zdvalue" placeholder="请输参数值" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="adminInfo" style="margin-top: 30px;width: 45%">保存</button>
                        <button id="cancel" type="button" class="layui-btn" style="margin-top: 30px;width: 45%;float:right">取消</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="../../static/js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/js/jquery.cookie.js"></script>
<script src="../../static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use(['form','element'], function() {
        var form = layui.form()
        re_url = "{{url_data|safe}}";

        form.verify({
            zdkey: function(value){
                if(value.length < 1){
                    return '字典编码不能为空!';
                }else if (value.length > 32){
                    return '字典编码不得大于32个字符!';
                }
            }
            ,zdvalue: function(value){
                if(value.length < 1){
                    return '字典名称不能为空!';
                }else if (value.length > 64){
                    return '字典名称不得大于64个字符!';
                }
            }
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        form.on('submit(adminInfo)', function(data){
            var index = layer.load(2, {shade: [0.2, '#5B5B5B']});

            $.ajax({
                url: 'dict_main_insert.html',
                type: 'POST',
                data:{'key': 'dic_main_insert','base':data.field,'type':re_url},
                headers:{'X-CSRFtoken':$.cookie('csrftoken')},
                success: function (base) {
                    if (base == 'true'){
                        layer.msg('操作成功！', {icon: 1});
                        //下面为跳出iframe框架的页面跳转
                        setTimeout("window.parent.location.reload();", 1300 )
                    }else if(base == 'false'){
                        layer.close(index);
                        layer.msg('参数名重复！', {icon: 2,time:1300});
                    }
                    else {
                        layer.close(index);
                        layer.msg('无权进行当前操作！', {icon: 2,time:1300});
                    }
                }
            })
            return false;
        });
        $("#cancel").click(function () {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);//关闭当前页
        })

    })
</script>
</body>
</html>